#pragma once
#include "stdafx.h"
#include <atlbase.h>
#include <atlcom.h>
#include <propkeydef.h>
#include <UIRibbon.h>

MIDL_INTERFACE("0a95e999-65b6-46db-b6d7-a7acf7767b19")
    IRibbonColorSetter : public IUnknown
    {
    public:
        virtual HRESULT STDMETHODCALLTYPE Initialize(REFPROPERTYKEY propertyKey, CComPtr<IUIFramework> pUIFramework); 
    };
 
class CRibbonColorSetter : public CComObjectRootEx<CComMultiThreadModel> , public IUICommandHandler, public IRibbonColorSetter
{
private:
	CComPtr<IUIFramework> _pUIFramework;
	UI_HSBCOLOR _originalColor;
	UI_HSBCOLOR _currentColor;
	PROPERTYKEY _propertyKey;

	HRESULT SetRibbonColor(UI_HSBCOLOR color);
	UI_HSBCOLOR ConvertRGBToHSB(COLORREF color);
		
public:
    BEGIN_COM_MAP(CRibbonColorSetter)
        COM_INTERFACE_ENTRY(IRibbonColorSetter)
		COM_INTERFACE_ENTRY(IUICommandHandler)
    END_COM_MAP()

	CRibbonColorSetter();
	virtual ~CRibbonColorSetter(void);

    virtual HRESULT STDMETHODCALLTYPE Initialize(REFPROPERTYKEY propertyKey, CComPtr<IUIFramework> pUIFramework); 

	HRESULT STDMETHODCALLTYPE Execute( 
            UINT32 commandId,
            UI_EXECUTIONVERB verb,
			const PROPERTYKEY *key,
            const PROPVARIANT *currentValue,
            IUISimplePropertySet *commandExecutionProperties);
        
	virtual HRESULT STDMETHODCALLTYPE UpdateProperty( 
            UINT32 commandId,
            REFPROPERTYKEY key,
            const PROPVARIANT *currentValue,
			PROPVARIANT *newValue) { return E_NOTIMPL;}
};
